package org.maitaole.controller;

import org.maitaole.model.Result;
import org.maitaole.service.ITbBrandService;
import org.maitaole.service.ITbCategoryBrandService;
import org.maitaole.service.ITbCategoryService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/index")
@CrossOrigin("*")
public class IndexController {

    @Resource
    private ITbCategoryService iTbCategoryService;

    @Resource
    private ITbCategoryBrandService iTbCategoryBrandService;

    @Resource
    private ITbBrandService iTbBrandService;

    @GetMapping("/category")
    public Result getAllCategory(){
        return Result.buildSuccess(iTbCategoryService.getAll());
    }

    @GetMapping("/findBrandId/{categoryId}")
    public Result getBrandIdByCategoryId(@PathVariable("categoryId") Integer categoryId){
        return Result.buildSuccess(iTbCategoryBrandService.getBrandIdByCategoryId(categoryId));
    }

    @GetMapping("/category-brand")
    public Result getAllByCategoryId(){
        return Result.buildSuccess(iTbCategoryService.getAllByCategoryId());
    }

    @GetMapping("/brand")
    public Result getAllBrand(){
        return Result.buildSuccess(iTbCategoryService.getAllByCategoryId());
    }

}
